package com.ysstech.kettle;


import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import com.ysstech.common.util.SpringContextUtil;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

/**
 *kettle管理启动类
 */
@MapperScan({"com.ysstech.kettle.mapper", "com.ysstech.common.mapper"})
@EnableCircuitBreaker
@EnableFeignClients
@EnableTransactionManagement
@SpringBootApplication(exclude = {MultipartAutoConfiguration.class, DruidDataSourceAutoConfigure.class})
public class KettleApplication {
    public static void main(String[] args) {
        ApplicationContext applicationContext = SpringApplication.run(KettleApplication.class, args);
        new SpringContextUtil().setApplicationContext(applicationContext);
    }

    @Bean(name = "multipartResolver")
    public MultipartResolver multipartResolver() {
        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
        resolver.setDefaultEncoding("UTF-8");
        resolver.setResolveLazily(true);//resolveLazily属性启用是为了推迟文件解析，以在在UploadAction中捕获文件大小异常
        resolver.setMaxInMemorySize(40960);
        resolver.setMaxUploadSize(5 * 1024 * 1024);//上传文件大小 50M 50*1024*1024
        return resolver;
    }

}
